
$(function(){
    ajaxUserHtml("");
    ajaxTjZxt("");
    ajaxTjBzt("");
});

var ajaxUserHtml = function(deptId){
    var urlz = "/integral/examJfpv/jfpvPage?deptId="+deptId;
    $.ajax({
        url : urlz,
        type : "get",
        dataType : "html",
        success : function(r) {
            $("#jfpvChild").html(r);
        }
    });
};

var setting = {
    showLine : true,
    view: {
        selectedMulti: false,
        showTitle : true
    },
    async: {
        enable: true,
        url:"/sys/dept/zTree",
        autoParam:["id"],
        type: "post",
        dataFilter: filter
    },
    data: {
        simpleData: {
            enable : true,
            idKey : "id",		// 结点的id,对应到Json中的id
            pIdKey : "pId"     // 结点的pId,对应到Json中的pId
        },
        key: {
            title: "title"
        }
    },
    callback : {
        onClick : showDetail			// 	点击节点时，显示节点详细信息
        ,
        onAsyncSuccess: zTreeOnAsyncSuccess  // 异步加载正
    }
};

function filter(treeId, parentNode, childNodes) {
    if (!childNodes) return null;
    for (var i=0, l=childNodes.length; i<l; i++) {
        childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
    }
    return childNodes;
}


//用于捕获异步加载正常结束的事件回调函数
function zTreeOnAsyncSuccess(event, treeId, treeNode, msg){
    var treeObj = $.fn.zTree.getZTreeObj(treeId);
    var nodes = treeObj.getNodes();
    if (nodes.length>0) {
        for(var i=0;i<nodes.length;i++){
            treeObj.expandNode(nodes[i], true, false, false);//默认展开第一级节点
        }
    }
}

$(document).ready(function(){
    cshData();
});

var cshData = function(){
    $.fn.zTree.init($("#departTreePt"), setting);
    /*$.ajax({
        async : false,
        cache:false,
        type: 'POST',
        dataType : "json",
        url: "/sys/dept/zTreeRoot",
        error: function () {//请求失败处理函数
            alert('请求失败');
        },
        success:function(data){ //请求成功后处理函数。
            //把后台封装好的简单Json格式赋给treeNodes
            $.fn.zTree.init($("#departTreePt"), setting,eval(data));
        }
    });*/
};


function showDetail(event, treeId, treeNode, clickFlag){
    var detpId = treeNode.id;
    ajaxUserHtml(detpId);
    ajaxTjZxt(detpId);
    ajaxTjBzt(detpId);
}



var ajaxTjZxt = function(deptId){
    var urlz = "/integral/examJfpv/examTjZxtData?deptId="+deptId;
    $.ajax({
        url : urlz,
        type : "get",
        dataType : "json",
        success : function(res) {
            var dom = document.getElementById("zxt");
            var myChart = echarts.init(dom);
            var option = {
                tooltip: {
                    trigger: 'axis'
                },
                xAxis: {
                    name:"月份",
                    type: 'category',
                    data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
                },
                yAxis: {
                    name:"学习人数",
                    type: 'value'
                },
                series: [{
                    name:'学习人数',
                    data: res.listObject,
                    type: 'line',
                    symbolSize: 5,
                    lineStyle: {
                        normal: {
                            color: 'green',
                            width: 4,
                            type: 'dashed'
                        }
                    },
                    itemStyle: {
                        normal: {
                            borderWidth: 3
                        }

                    }
                }]
            };
            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        }
    });
};


var ajaxTjBzt = function(deptId){
    var urlz = "/integral/examJfpv/examTjBztData?deptId="+deptId;
    $.ajax({
        url : urlz,
        type : "get",
        dataType : "json",
        success : function(res) {
            var dom = document.getElementById("bzt");
            var myChart = echarts.init(dom);
            var option = {
                title: {
                    text: '本月学习统计',
                    x: 'left'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    right: 10,
                    top: 20,
                    bottom: 20,
                    data: ["已学习人数","未学习人数"]
                },
                series: [
                    {
                        type: 'pie',
                        radius: '60%',
                        center: ['40%', '50%'],
                        data: res.listData,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        }
    });
};
